package com.ddstation.common.service;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ddstation.constant.SewageConstant;
import com.ddstation.crud.entity.MaInvsRegisterAbnormalRuleEntity;
import com.ddstation.crud.mapper.MaInvsRegisterAbnormalRuleMapper;

@Service
public class RegisterAbnormalRuleServiceImpl implements RegisterAbnormalRuleService {
	// 查询
	@Override
	@Transactional(readOnly=true)
	public List<MaInvsRegisterAbnormalRuleEntity> searchAbnormalRuleList(
			String invsInstitutionId,
			Integer catalogId,
			Integer ruleId){
		
		// 查询指定机构的check rule
		List<MaInvsRegisterAbnormalRuleEntity> ruleList = maInvsRegisterAbnormalRuleMapper.selectByInstitutionCatalogId(
						invsInstitutionId,catalogId,ruleId);
		
		// 存在时直接返回
		if (ruleList != null && ruleList.size() > 0){
			return ruleList;
		}	
		// 不存在时,按共通值
		ruleList = maInvsRegisterAbnormalRuleMapper.selectByInstitutionCatalogId(
					SewageConstant.INVS_COMMON_INSTITUTION, 
					catalogId,
					ruleId);
		return ruleList;
	}
	
	@Inject private MaInvsRegisterAbnormalRuleMapper maInvsRegisterAbnormalRuleMapper;
}
